package su.mysrpingbootprojects.hibernatedemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import java.util.List;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class HibernateDemoApplication implements ApplicationRunner {

	private final StudentService studentService;

	@Autowired
	public HibernateDemoApplication(StudentService studentService) {
		this.studentService = studentService;
	}

	public static void main(String[] args) {
		SpringApplication.run(HibernateDemoApplication.class, args);
	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		studentService.fillStudentTable();
		List<Student> studentList = studentService.getStudentsList();
		studentList.stream().forEach(System.out::println);
	}

}
